checkLogin();

//获取地址详细信息
var address = getCache(address_key);
address = JSON.parse(address);
if(address == undefined || address == null || address == ''){
    history.go(-1);
}
console.log(address)
$('.name').val(address.name);
$('.mobile').val(address.mobile);
$('.area_info').val(address.area_info);
$('.address').val(address.address);

//将默认的地址信息放入隐藏域
$("#province_id").val(address.province_id);
$("#city_id").val(address.city_id);
$("#area_id").val(address.area_id);
/*
$('#button').on('tap',function () {
    getData(address_edit,combineParams())
})*/



var province_id = 0;
var city_id = 0;
var area_id = 0;

var _getParam = function(obj, param) {
    return obj[param] || '';
};
var cityPicker3 = new mui.PopPicker({
    layer: 3
});

cityPicker3.setData(cityData3);
cityPicker3.pickers[0].setSelectedIndex(0);
cityPicker3.pickers[0].setSelectedValue('110000');
cityPicker3.pickers[1].setSelectedIndex(0);
cityPicker3.pickers[1].setSelectedValue('110000');
cityPicker3.pickers[2].setSelectedIndex(0);
cityPicker3.pickers[2].setSelectedValue('110101');
var showCityPickerButton = document.getElementById('showCityPicker3');
var edit_right = document.getElementsByClassName('edit-right')[2];

//监听重选地址
showCityPickerButton.addEventListener('tap', function(event) {
    cityPicker3.show(function(items) {
        edit_right.value =  _getParam(items[0], 'text') + " " + _getParam(items[1], 'text') + " " + _getParam(items[2], 'text');
        $("#province_id").val(_getParam(items[0], 'value'));
        $("#city_id").val(_getParam(items[1], 'value'));
        $("#area_id").val(_getParam(items[2], 'value'));
        //返回 false 可以阻止选择框的关闭
        //return false;
    });
}, false);

var id = address.id;

//验证表单并处理登录交互

var ajaxOption = {
    url: address_edit,
    method: 'POST',
    data:combineParams({id:id}),
    success: function (res) {
        setTimeout(function () {
            redirect('address.html');
        },2000);
    }
};

var is_mobile = function(e) {
    var status = true;
    if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test( $(e).val()))){
        status = false;
    }
    return {
        status: status, // or false
        message: '请填写正确的手机号'
    };
}

checkform($('#myForm'), ajaxOption);

//点选输入框时 颜色变化
$('.edit-container').on('tap',function () {
    var type = parseInt(this.getAttribute('data'));
    if(type == undefined || type == null || type == ''){
        return;
    }
    $('.edit-container').removeClass('border_color');
    $('.change'+type).addClass('border_color');

})


//获取原始窗口的高度
var originalHeight=document.documentElement.clientHeight || document.body.clientHeight;
window.onresize=function(){
    //软键盘弹起与隐藏  都会引起窗口的高度发生变化
    var  resizeHeight=document.documentElement.clientHeight || document.body.clientHeight;
    if(resizeHeight*1<originalHeight*1){ //resizeHeight<originalHeight证明窗口被挤压了
        $('.sure-submit').css('display','none');
        /*$(".mui-iframe-wrapper").css('bottom','0px');*/
    }else{
        $('.sure-submit').css('display','block');
        /*$(".mui-iframe-wrapper").css('bottom','50px');*/
    }
}

